<?php
/**
 * The sidebar containing the main widget area.
 *
 * 
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */
?>
	<?php 
	$tlset = get_option( 'tlset' );
	global $wp_query;
	$curquer = $wp_query->get_queried_object();
	$sbarname = '';
	$sb = 'cro_sidebarmain';
	$pt = get_post_type();
	if (is_category()){		
		$opt = get_option('taxonomy_'. $curquer->term_id);
		$sbarname = $opt['cro_cat_sbar'];
		$sb = ($sbarname != '' && $sbarname !== '0') ? 'cro_' . $sbarname : 'cro_sidebarmain' ;
	
	} elseif (is_tax('series')){
		if (isset($tlset['cro_podbar']) && $tlset['cro_podbar'] != '0' ) {
			$sb = 'cro_' . $tlset['cro_podbar'];
		} else {
			$opt = get_option('taxonomy_'. $curquer->term_id);
			$sbarname = $opt['cro_ser_sbar'];
			$sb = ($sbarname != '' && $sbarname !== '0') ? 'cro_' . $sbarname : 'cro_sidebarmain' ;
		}
	
	} elseif (is_tax('sermon_tags')){
		if (isset($tlset['cro_podbar']) && $tlset['cro_podbar'] != '0' ) {
			$sb = 'cro_' . $tlset['cro_podbar'];
		} else {
			$opt = get_option('taxonomy_'. $curquer->term_id);
			$sbarname = $opt['cro_ser_sbar'];
			$sb = ($sbarname != '' && $sbarname !== '0') ? 'cro_' . $sbarname : 'cro_sidebarmain' ;
		}
	} elseif (is_single()) {
		if ($pt == 'sermons' && isset($tlset['cro_podbar']) && $tlset['cro_podbar'] != '0' ) {
			$sb = 'cro_' . $tlset['cro_podbar'];
		} else {
			$sbarname = get_post_meta($curquer->ID, 'cro_sidebarsel',true);
			$sb = ($sbarname != '' && $sbarname !== '0') ? 'cro_' . $sbarname : 'cro_sidebarmain' ;
		}
	} elseif (is_page()) {
		$sbarname = get_post_meta($curquer->ID, 'cro_sidebarsel',true);
		$sb = ($sbarname != '' && $sbarname !== '0') ? 'cro_' . $sbarname : 'cro_sidebarmain' ;
	} elseif (is_archive()){
		if ($pt == 'sermons' && isset($tlset['cro_podbar']) && $tlset['cro_podbar'] != '0' ) {
			$sb = 'cro_' . $tlset['cro_podbar'];
		}
	}
	?>
	<?php if ( is_active_sidebar( $sb ) ) : ?>
		<ul class="mainwidget widgside widginside">
			<?php dynamic_sidebar( $sb ); ?>
		</ul><!-- #secondary -->
	<?php endif; ?>